

use "$clean/clean_all.dta" ,clear





cap gen coeff=. in 1/15
cap gen u_se=. in 1/15
cap gen l_se=. in 1/15
cap gen coeff_t=. in 1/15
cap gen u_se_t=. in 1/15
cap gen l_se_t=. in 1/15
cap gen time_week=_n in 1/15

global contr 

*** Use pre-treatment weeks ***

forval l=2/4 {
local k=5-`l'
local q=5-`l'+1
egen temp=rowmax(canvass_any_n`k'week canvass_any_n`q'week)
replace canvass_any_n`k'week= temp
drop temp
}

forval l=1/4 {
local k=5-`l'
reg canvass_any_n`l'week $contr if treatment==0, robust
replace coeff=_b[_cons] in `k'
replace u_se=_b[_cons]+1*_se[_cons] in `k'
replace l_se=_b[_cons]-1*_se[_cons] in `k'


reg canvass_any_n`l'week $contr  if treatment==1, robust
replace coeff_t=_b[_cons] in `k'
replace u_se_t=_b[_cons]+1*_se[_cons] in `k'
replace l_se_t=_b[_cons]-1*_se[_cons] in `k'

}

egen temp=rowmax(canvass_any_n1week canvass_any_0week)
replace canvass_any_0week= temp
drop temp

reg canvass_any_0week $contr if treatment==0, robust
replace coeff=_b[_cons] in 5
replace u_se=_b[_cons]+1*_se[_cons] in 5
replace l_se=_b[_cons]-1*_se[_cons] in 5


reg canvass_any_0week $contr  if treatment==1, robust
replace coeff_t=_b[_cons] in 5
replace u_se_t=_b[_cons]+1*_se[_cons] in 5
replace l_se_t=_b[_cons]-1*_se[_cons] in 5


forval l=1/8 {
local k=`l'-1
egen temp=rowmax(canvass_any_`k'week canvass_any_`l'week)
replace canvass_any_`l'week= temp
drop temp
}


forvalue l=1/8 {
local k=`l'+5
reg canvass_any_`l'week $contr  if treatment==0, robust
replace coeff=_b[_cons] in `k'

replace u_se=_b[_cons]+1*_se[_cons] in `k'
replace l_se=_b[_cons]-1*_se[_cons] in `k'

reg canvass_any_`l'week $contr   if treatment==1, robust
replace coeff_t=_b[_cons] in `k'
replace u_se_t=_b[_cons]+1*_se[_cons] in `k'
replace l_se_t=_b[_cons]-1*_se[_cons] in `k'
}

drop if time_week>13

twoway line coeff time_week || rcap u_se l_se time_week ///
|| line coeff_t time_week || rcap u_se_t l_se_t time_week , ytitle("Fraction of active supporters", ) xtitle("Weeks relative to treatment")  ///
 , legend(order( 1 "Control" 3 "Treatment" ///
2 "One standard error interval"  ) pos(6) rows(2)) ///
ysc(range(0 0.20)) ylab(-0.1(0.1)0.20) xlab( 1 "-4" 2 "-3" 3"-2" 4 "-1" 5 "0" 6"1" 7"2" 8"3" 9"4" 10"5" 11"6" 12"7" 13 "8" ) ///
xsc(range(1 13))  ylab( 0 (0.1) 0.2)  xline(5.5, lcolor(red))


graph export "$figures/Figure_1.pdf",  replace as(pdf)






